cmake_minimum_required(VERSION 2.8.3)
project(rgbd_module)


set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}  -Wall  -O3 -march=native ")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall  -O3 -march=native")

# Check C++11 or C++0x support
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
    add_definitions(-DCOMPILEDWITHC11)
    message(STATUS "Using flag -std=c++11.")
elseif(COMPILER_SUPPORTS_CXX0X)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
    add_definitions(-DCOMPILEDWITHC0X)
    message(STATUS "Using flag -std=c++0x.")
else()
    message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()


## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
    roscpp
    std_msgs
    cv_bridge
    tf
    tf2
    tf2_ros
    hi_slam
    pluginlib
    roslib
    )

find_package(OpenCV 3.0 QUIET)
if(NOT OpenCV_FOUND)
    find_package(OpenCV 2.4.3 QUIET)
    if(NOT OpenCV_FOUND)
        message(FATAL_ERROR "OpenCV > 2.4.3 not found.")
    endif()
endif()
find_package(Eigen3 3.1.0 REQUIRED)
find_package(Pangolin REQUIRED)



catkin_package(
    INCLUDE_DIRS include
    LIBRARIES rgbd_module
    CATKIN_DEPENDS
    roscpp
    pluginlib
    #  DEPENDS system_lib
    )

include_directories(
    include
    ${catkin_INCLUDE_DIRS}
    ${PROJECT_SOURCE_DIR}
    ${PROJECT_SOURCE_DIR}/include
    ${PROJECT_SOURCE_DIR}/../orb_slam2
    ${PROJECT_SOURCE_DIR}/../orb_slam2/include
    ${Pangolin_INCLUDE_DIRS}
    )

set(LIBS
    ${catkin_LIBRARIES}
    ${OpenCV_LIBS}
    ${EIGEN3_LIBS}
    ${Pangolin_LIBRARIES}
    ${PROJECT_SOURCE_DIR}/../orb_slam2/Thirdparty/DBoW2/lib/libDBoW2.so
    ${PROJECT_SOURCE_DIR}/../orb_slam2/Thirdparty/g2o/lib/libg2o.so
    ${PROJECT_SOURCE_DIR}/../orb_slam2/lib/liborb_slam2.so
    )


## Declare a C++ library
add_library(rgbd_module
    src/slam.cpp
    src/map_publisher.cpp
    src/image_grabber.cpp
    )
target_link_libraries(rgbd_module
    ${LIBS}
    )

add_executable(main
    src/main.cpp
    src/slam.cpp
    src/map_publisher.cpp
    src/image_grabber.cpp)
target_link_libraries(main
    ${LIBS})

